home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Application: StdPix */
- /* */
- /* Files: StdPix.π */
- /* StdPix.π.rsrc */
- /* StdPix.c */
- /* */
- /* Programmer: Edgar Lee */
- /* Organization: Apple Computer, Inc. */
- /* Department: Developer Technical Support, DTS */
- /* Language: C (Think C version 5.0.2) */
- /* Date Created: 09-24-92 */
- /* */
- /****************************************************************************/
-
- #include <ImageCompression.h>
-
- /* Constant Declarations */
-
- #define WWIDTH 170
- #define WHEIGHT 145
-
- #define WLEFT (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2)
- #define WTOP (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2)
-
- /* Global Variable Definitions */
-
-
- void initMac();
-
- void createWindow();
- void doEventLoop();
-
- void doBottleneckTest();
-
- main()
- {
- initMac();
-
- createWindow();
-
- doEventLoop();
- }
-
- void initMac()
- {
- MaxApplZone();
-
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
- FlushEvents( 0, everyEvent );
- }
-
- void createWindow()
- {
- Rect rect;
- WindowPtr window;
-
- SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
- window = NewCWindow( 0L, &rect, "\pStdPix", true, documentProc,
- (WindowPtr)-1L, true, 0L );
- SetPort( window );
-
- TextMode( srcCopy );
- TextSize( 9 );
- TextFont( geneva );
- }
-
- void DrawDepth( short depth, int col, int row)
- {
- MoveTo( col, row );
- if (depth != -1)
- switch(depth) {
- case 1:
- DrawString("\pQuickTime 1-bit");
- break;
- case 2:
- DrawString("\pQuickTime 2-bit");
- break;
- case 4:
- DrawString("\pQuickTime 4-bit");
- break;
- case 8:
- DrawString("\pQuickTime 8-bit");
- break;
- case 16:
- DrawString("\pQuickTime 16-bit");
- break;
- case 24:
- DrawString("\pQuickTime 24-bit");
- break;
- case 32:
- DrawString("\pQuickTime 32-bit");
- break;
- default:
- DrawString("\pQuickTime image");
- break;
- }
- else
- DrawString("\pQuickDraw image");
- }
-
-
-
- short gDepth = -1;
-
- pascal void myStdPix( PixMapPtr src, Rect *srcRect, MatrixRecordPtr matrix,
- short mode, RgnHandle mask, PixMapPtr matte,
- Rect *matteRect, short flags )
- {
- ImageDescriptionHandle desc;
- Ptr data;
- long bufferSize;
-
- GetCompressedPixMapInfo( src, &desc, &data, &bufferSize, nil, nil );
- gDepth = (**desc).depth;
- }
-
- pascal void myTextProc( short byteCount, Ptr textBuf, Point numer, Point denom ){}
- pascal void myLineProc( Point newPt ){}
- pascal void myRectProc( GrafVerb verb, Rect *r ){}
- pascal void myRRectProc( GrafVerb verb, Rect *r, short ovalWidth, short ovalHeight ){}
- pascal void myOvalProc( GrafVerb verb, Rect *r ){}
- pascal void myArcProc( GrafVerb verb, Rect *r, short startAngle, short arcAngle ){}
- pascal void myPolyProc( GrafVerb verb, PolyHandle poly ){}
- pascal void myRgnProc( GrafVerb verb, RgnHandle rgn ){}
- pascal void myBitsProc( BitMap *bitPtr, Rect *srcRect, Rect *dstRect,
- short mode, RgnHandle maskRgn ){}
-
-
- void GetQTImagePixelDepth(PicHandle picture)
- {
- CQDProcs bottlenecks;
-
- /* Define our own bottlenecks. */
- SetStdCProcs( &bottlenecks );
-
- bottlenecks.textProc = (Ptr)myTextProc;
- bottlenecks.lineProc = (Ptr)myLineProc;
- bottlenecks.rectProc = (Ptr)myRectProc;
- bottlenecks.rRectProc = (Ptr)myRRectProc;
- bottlenecks.ovalProc = (Ptr)myOvalProc;
- bottlenecks.arcProc = (Ptr)myArcProc;
- bottlenecks.polyProc = (Ptr)myPolyProc;
- bottlenecks.rgnProc = (Ptr)myRgnProc;
- bottlenecks.bitsProc = (Ptr)myBitsProc;
- bottlenecks.newProc1 = (Ptr)myStdPix; /* pixProc */
-
- /* Install our custom bottlenecks to intercept any compressed images. */
- (*(qd.thePort)).grafProcs = (QDProcs *)&bottlenecks;
- DrawPicture( picture, &((**picture).picFrame) );
-
- /* Switch back to the default procs. */
- (*(qd.thePort)).grafProcs = 0L;
- }
-
- void doBottleneckTest()
- {
- int i;
- PicHandle picture;
- Rect rect;
-
- for (i = 0; i < CountResources( 'PICT' ); i++)
- {
- // Load picture
- picture = (PicHandle)Get1IndResource( 'PICT', i + 1 );
-
- GetQTImagePixelDepth(picture);
-
- // Display picture
- rect = (**picture).picFrame;
- OffsetRect( &rect, -rect.left, -rect.top );
- OffsetRect( &rect, 10, ((rect.bottom - rect.top) + 10) * i + 10 );
- DrawPicture( picture, &rect );
-
- // Free any memory used by the picture.
- ReleaseResource( picture );
-
- // Display the compression depth
- DrawDepth( gDepth, rect.right + 10, rect.top + 10 );
- gDepth = -1;
- }
- }
-
- void doEventLoop()
- {
- EventRecord event;
- WindowPtr window;
- short clickArea;
- Rect screenRect;
-
- for (;;)
- {
- if (WaitNextEvent( everyEvent, &event, 0, nil ))
- {
- if (event.what == mouseDown)
- {
- clickArea = FindWindow( event.where, &window );
-
- if (clickArea == inDrag)
- {
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragWindow( window, event.where, &screenRect );
- }
- else if (clickArea == inContent)
- {
- if (window != FrontWindow())
- SelectWindow( window );
- }
- else if (clickArea == inGoAway)
- if (TrackGoAway( window, event.where ))
- return;
- }
- else if (event.what == updateEvt)
- {
- window = (WindowPtr)event.message;
- SetPort( window );
-
- BeginUpdate( window );
- doBottleneckTest();
- EndUpdate( window );
- }
- }
- }
- }